<template>
    <div class="contract-list-page contract-cancellation-list">
        <Card>
            <ChangeForm
                :isSP="isSP"
                :formValidate="formValidate"
                :formValidateRule="formValidateRule"
                :dataDict="dataDict"
                :businessSource="businessSource"
                @showModal="showModal"
                @getList="getList"
                :loading="loading"
            />
       <ChangeTable
                :isSP="isSP"
                :formValidate="formValidate"
                :dataDict="dataDict"
                :contractTable="contractTable"
                :businessSource="businessSource"
                @handleRevoke="handleRevoke"
                @showDetail="showDetail"
                @getList="getList"
            />
        </Card>
        <ActivatedCase
            :isSP="isSP"
            :getDataFn="getDataFn"
            :contractBusiness="contractBusiness"
            :handleBusiness="'collectionRevoke'"
            :dataDict="dataDict"
            :modal="modal"
            :modalTitle="modalTitle"
            @showContractDetial="showContractDetial"
            @closeModal="closeModal"
        />
        <div v-if="detailModel">
            <Modal v-model="detailModel" :title="detailTitle" :width="1000" :closable="false"
                   :mask-closable="false">
                <ChangeDetailTable
                    :spinShow="spinShow"
                    :isSP="isSP"
                    :Obj="Obj"
                    :loading="loading"
                    :dataDict="dataDict"
                    @closeSpin="closeSpin"
                    @showSpin="showSpin"
                />
                <div slot="footer">
                    <Button size="small" @click="detailModel = false">返回</Button>
                </div>
            </Modal>
        </div>
    </div>
</template>
<script>
    // api
    import {
        queryManageCollectCancelList,
        getBasicCancelList,
        getBasicCancelLoanList
    } from "_p/basic/api/contract/revoke/revoke-collection";
    import {mapActions, mapGetters} from "vuex";
    import ChangeForm from "./ChangeForm";
    import ChangeTable from "./ChangeTable";
    import {getDictDataList} from "_p/basic/assets/contract/js/utils";
    import {isPhoneValiate} from "_p/basic/assets/contract/js/utils";
    import {businessSource, channelType} from "_p/basic/api/contract/channel-type/channel-type";
    import ActivatedCase from "_p/basic/pages/contract/common/activated-case/index";
    import ChangeDetailTable from "../ChangeDetailTable";
    export default {
        name: "index",
        components: {
            ChangeForm,
            ChangeTable,
            ChangeDetailTable,
            ActivatedCase
        },
        props: {},
        data() {
            return {
                pageNo: 1,
                loading: false,
                detailModel:false,
                spinShow:false,
                // 日期区间
                isDateErr: false,
                Obj:{},
                contractBusiness: ["collectionRevoke"],
                formValidate: {
                    applyNo: "", // 申请编号
                    certNo: "", // 证件号码
                    contractNo: "", // 合同号
                    contractStatusEnum: null, // 合同状态 contractCancel

                    custName: "", // 客户名称
                    endDate: "", //合同到期时间  结束时间
                    startDate: "", //合同激活时间 申请时间
                    phone: "", //手机号码
                    pageNumber: 1, // integer($int32) // 当前页
                    pageSize: 50 //integer($int32) // 多少条
                },
                formValidateRule: {
                    phone: [
                        {
                            validator: (rule, value, callback) => {
                                isPhoneValiate(rule, value, callback);
                            },
                            trigger: "blur"
                        }
                    ]
                },

                contractTable: {
                    current: 1, // 表格当前页
                    pages: 0,
                    searchCount: false,
                    size: 10,
                    total: 0,
                    orders: [],
                    records: []
                },
                dicttArr: ["bankCode","processStatus", "businessSource", "PersonRoleType", "contractStatus", "channelType",
                    "creditStatus","receiptSourceType","feeType"],
                // selct 数据字典
                dataDict: {},
                modalTitle: "",
                modal: false
            };
        },

        computed: {
            ...mapGetters({
                userInfo: "userInfo",
                roleType: "roles",
            }),
            // 是否是合作商
            isSP: function () {
                return channelType(this.roleType)
                // return true;
            },
            getDataFn: function () {
                if (this.isSP) {
                    return getBasicCancelLoanList;
                } else {
                    return getBasicCancelList;
                }

            }
        },
        created() {
            this.isSP = channelType(this.$route.meta.params);
            // businessSource 通过 roleType 获取 值: BUSINESS_PEOPLE / SP
            this.businessSource = businessSource(this.roleType);
        },
        mounted() {
            this.init();
        },
        activated() {
            this.getList(this.formValidate);
        },
        methods: {
            ...mapActions(["getDictData"]),
            init() {
                // 数据字典
                this.getDictDataList();
            },
            getDictDataList() {
                getDictDataList(this.dicttArr).then(res => {
                    this.dataDict = res;
                });
            },
            getList(data) {
                this.loading = true;
                queryManageCollectCancelList(data).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.contractTable = res.data;
                    } else {
                        this.$Message.error("Fail!");
                    }
                }).catch(e => {
                    this.loading = false;
                });
            },
            // 弹窗
            showModal() {
                this.modalTitle = "已激活案件列表";
                this.modal = true;
            },
            closeModal() {
                this.modal = false;
            },
            // 分配明细
            showDetail(row) {
                this.Obj.contractNo = row.contractNo;
                this.Obj.receiptId = row.receiptId;
                this.detailModel = true;
            },
            showContractDetial(params) {
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/revoke-collection/revoke-list/index",
                    "收款详情",
                    "ios-add",
                    params,
                    "revoke-detial-" + params.contractNo,
                    [],
                    true
                );
            },
            handleRevoke(params,type){
                params.type = type;
                params.editFlag = true;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/revoke-collection/revoke-collection-detial/index",
                    "收款撤销",
                    "ios-add",
                    params,
                    "revoke-collection-detial-" + params.id,
                    [],
                    true
                );
            }

        },
    };
</script>
<style lang="less">
    @import "../../../../styles/common/form.less";

</style>
